type 'a graph_term = {nodes : 'a list;  edges : ('a * 'a) list};;

(* 图g、节点a、条件函数cond *)
let neighbors g a cond =
  let edge l (b,c) = if b = a && cond c then c :: l
                    else if c = a && cond b then b :: l
                    else l in
  List.fold_left edge [] g.edges

let rec list_path g a to_b = match to_b with
  | [] -> assert false (* [to_b] contains the path to [b]. *)
  | a' :: _ ->
    if a' = a then [to_b]
    else
      let n = neighbors g a' (fun c -> not(List.mem c to_b)) in
      List.concat(List.map (fun c -> list_path g a (c :: to_b)) n)

let paths g a b =
  assert(a <> b);
  list_path g a [b];;

let example_graph =
    {nodes = ['b'; 'c'; 'd'; 'f'; 'g'; 'h'; 'k'];
     edges = [('h', 'g'); ('k', 'f'); ('f', 'b'); ('f', 'c'); ('c', 'b')]};;

paths example_graph 'f' 'b';;